package neusoft.yuejian_11.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.List;

import neusoft.yuejian_11.adapter.EinfomationListAdapter;
import neusoft.yuejian_11.base.BaseActivity;
import neusoft.yuejian_11.bean.ActivitynInBean;
import neusoft.yuejian_11.bean.GetInfo;
import neusoft.yuejian_11.listener.RetrofitListener;
import neusoft.yuejian_11.model.EventModel;
import neusoft.yuejian_11.model.UserModel;
import neusoft.yuejian_11.R;

public class InformationEActivity extends BaseActivity implements RetrofitListener{
    protected Context context;
    private int activityId;
    private ImageButton imageButtonBack;
    private EinfomationListAdapter adapter;
    private RecyclerView recyclerView;
    private TextView textViewUserName;
    private TextView textViewUserPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information_e);

        initViews();//初始化
        initEvents();//点击事件处理
        initData();//网络获取

        activityId = getIntent().getIntExtra("a_id",-1);
    }

    private void initViews() {
        imageButtonBack = (ImageButton) findViewById(R.id.imageButtom_back);

        textViewUserName = (TextView) findViewById(R.id.text_user_name);
        textViewUserPhone = (TextView) findViewById(R.id.text_user_phone);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    }

    private void initEvents() {
        imageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    private void initData() {
        EventModel eventModel = new EventModel();
        eventModel.eventnInList(getU_id(),this);

        UserModel userModel = new UserModel();
        userModel.getUserInfo(getU_id(),this);
    }

    @Override
    public void onSuccess(Object o, int flag) {
        if (flag==1) {
            List<ActivitynInBean> activitynInBeanList = (List<ActivitynInBean>) o;
            adapter = new EinfomationListAdapter(InformationEActivity.this, activitynInBeanList);
            LinearLayoutManager layoutManager = new LinearLayoutManager(InformationEActivity.this);
            layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            recyclerView.setLayoutManager(layoutManager);
            recyclerView.setAdapter(adapter);
            recyclerView.setItemAnimator(new DefaultItemAnimator());
        }
        if (flag==2){
            GetInfo getInfo = (GetInfo) o;
            textViewUserName.setText(getInfo.getU_name());
            textViewUserPhone.setText(getInfo.getU_phone());
        }

    }

    @Override
    public void onFail() {

    }
}
